﻿using System;
using System.Collections.Generic;
using System.Text;
using UtilZ.Dotnet.Ex.Base;

namespace UtilZ.Dotnet.Ex.Communication.Net.Telnet.KeyCommands
{
    internal class DeleteCommand : TelnetKeyCommandAbs
    {
        /**********************************************
         *          Backspace           Delete
         * windows  8                   127
         * linux    127                 27-91-51-126
         * mac      127                 27-91-51-126
         **********************************************/

        public DeleteCommand()
              : base()
        {

        }

        protected override bool PrimitveProcess(ListenTelnetClient telnetClient, byte[] data, int revicedDataLength)
        {
            if (revicedDataLength == 1 && telnetClient.Platform == OSPlatformID.Win && data[0] == 127 ||
                revicedDataLength == 4 && (telnetClient.Platform == OSPlatformID.Linux_Unix || telnetClient.Platform == OSPlatformID.MacOS) && data[0] == 27 && data[1] == 91 && data[2] == 51 && data[3] == 126)
            {
                telnetClient.DeleteCurrsorRightChars(1);
                return true;
            }

            return false;
        }
    }
}
